﻿using IrrlichtLime;
using System.Collections.Generic;

namespace Iso
{
    public static class Keyboard
    {
        public static void Register(IrrlichtDevice device)
        {
            device.OnEvent += new IrrlichtDevice.EventHandler(device_OnKeyEvent);
        }

        public static Dictionary<KeyCode, bool> KeyIsDown = new Dictionary<KeyCode, bool>();

        private static bool device_OnKeyEvent(Event e)
        {
            if (e.Type == EventType.Key)
            {
                if (KeyIsDown.ContainsKey(e.Key.Key))
                    KeyIsDown[e.Key.Key] = e.Key.PressedDown;
                else
                    KeyIsDown.Add(e.Key.Key, e.Key.PressedDown);
            }

            return false;
        }

        public static bool IsKeyDown(KeyCode keyCode)
        {
            return KeyIsDown.ContainsKey(keyCode) ? KeyIsDown[keyCode] : false;
        }

        public static void Reset()
        {
            KeyIsDown = new Dictionary<KeyCode, bool>();
        }
    }
}
